﻿using System;
using System.Web.Configuration;

namespace VioletDevelopmentLaboratory.Net.Web.Configuration
{
	public sealed class HttpHandlersSectionManager : ConfigurationManagerBase
	{
		private HttpHandlersSection section;

		public HttpHandlersSectionManager()
		{
			this.section = (HttpHandlersSection)base.GetConfigurationSection("system.web/httpHandlers");
		}

		public void AddHandler(string path, string type, string verb, bool validate)
		{
			this.section.Handlers.Add(new HttpHandlerAction(path, type, verb, validate));
			this.Save();
		}
		public void ModifyHandler(int index, string path, string type, string verb, bool validate)
		{
			this.section.Handlers[index].Path = path;
			this.section.Handlers[index].Type = type;
			this.section.Handlers[index].Verb = verb;
			this.section.Handlers[index].Validate = validate;
			this.Save();
		}
		public void RemoveHandler(int index)
		{
			this.section.Handlers.RemoveAt(index);
			this.Save();
		}
		public void ClearHandlers()
		{
			this.section.Handlers.Clear();

			this.Save();
		}
		public HttpHandlerAction GetHandler(int index)
		{
			return this.section.Handlers[index];
		}
		public HttpHandlerActionCollection GetHandlers()
		{
			return this.section.Handlers;
		}
	}
}
